package com.itheima.web.manager;

import cn.hutool.core.util.ArrayUtil;
import com.itheima.domain.mongo.Movement;
import com.itheima.service.mongo.MovementService;
import com.itheima.vo.ErrorResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.bson.types.ObjectId;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

@Component
public class MovementManager {
    @DubboReference
    MovementService movementService;
    //动态审核通过
    public ResponseEntity movementPass(String[] moveIds) {
        //1.判断字符串数组是否为空
        if (ArrayUtil.isNotEmpty(moveIds)) {
            for (String moveId : moveIds) {
                //1.1 获取单个动态Id，根据动态id查询动态详情
                Movement movement = movementService.findById(new ObjectId(moveId));
                //1.2 更改状态码
                movement.setState(1);
                movementService.update(movement);
            }
            String message="操作成功！";
            return ResponseEntity.ok(message);
        }
       return ResponseEntity.status(500).body(ErrorResult.error());
    }
    //动态审核拒绝
    public ResponseEntity movementReject(String[] movementIds) {
        //1.遍历数组获取动态的Id
        if (ArrayUtil.isNotEmpty(movementIds)) {
            for (String movementId : movementIds) {
                Movement movement = movementService.findById(new ObjectId(movementId));
                movement.setState(2);
                movementService.update(movement);
            }
            return ResponseEntity.ok("操作成功！");
        }
        return ResponseEntity.status(500).body(ErrorResult.error());
    }
}
